<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:bw="http://tice2.univ-reunion.fr/babelweb"
    >
    <xsl:import href="manifest-manager.xsl"/>
    <xsl:import href="babel-transform-fly.xsl"/>
    <xsl:import href="conf/babel-web-conf.xsl"/>
    
    <xsl:output method="xml" name="xml" indent="yes" encoding="utf-8" />
    <xsl:output method="html" indent="yes" name="html"/>
    
    <xsl:template match="/">
        <xsl:variable name="s">&lt;?xml-stylesheet href="/babel-data/transform/babel-transform-fly.xsl" type="text/xsl"?&gt;</xsl:variable>
        
<!--        EDITION OF XSL FILE FOR WEB-->
        <!--<xsl:result-document href="/Library/WebServer/Documents/babel-data/online-editing/edit-babel-fly.html">
            <html>
                <head><title>Editing output model</title>
                    <link rel="stylesheet" type="text/css" href="/Xopus/examples/Simple/css/common.css"/>
                    <script type="text/javascript" src="/Xopus/xopus/xopus.js"></script>
                </head>
                <body>
                    <div xopus="true" autostart="true">
                        <xml><x:config xmlns:x="http://www.xopus.com/xmlns/config" version="1.0">
                            <x:javascript src="save.js"/>
                            <x:pipeline xml="{$webAddressToActivities}/transform/babel-transform-fly.xsl" 
                                xsd="/babel-data/online-editing/babel-transform-schema.xsd">
                                <x:view name="WYSIWYG View">
                                    <x:transform xsl="/babel-data/online-editing/modify-transform-fly.xsl"/>
                                </x:view>
                            </x:pipeline>
                        </x:config></xml>
                    </div>
                </body>
            </html>
        </xsl:result-document>-->
        
        
        <xsl:for-each select="//babelweb-data">
            <xsl:variable name="modulename">
                <xsl:choose>
                    <xsl:when test="substring(assessmentItem/@module,1,3) = 'm10'">m10</xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="substring(assessmentItem/@module,1,2)"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            
            <xsl:variable name="modulelang" select="assessmentItem/@lang"/>
            <xsl:variable name="filename" select="concat(assessmentItem/@identifier,'.xml')"/>
            <xsl:variable name="fileloc" select="concat('../course_intermediate/',$modulename,'/',$modulelang,'/',assessmentItem/@identifier,'.xml')"/>
            <xsl:variable name="filenameSA" select="concat('../course_html/',$modulename,'/',$modulelang,'/',assessmentItem/@identifier,'.html')"/>
            <xsl:variable name="editfilename" select="concat('/Library/WebServer/Documents/babel-data/online-editing/', $modulename, '/',
                $modulelang,'/',assessmentItem/@identifier,'.html')"/>
            
            <!--<xsl:result-document href="{$filenameSA}">
                <xsl:for-each select="assessmentItem">
                <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
                <link href="../sources/styles/style.css" rel="stylesheet" type="text/css"/>
                
                <!-!-[if IE]>
                <link rel="stylesheet" href="<?php echo $this->baseurl ?>/sources/styles/ie_fixes.css" type="text/css" />
                <![endif]-!->
            
            <script type="text/javascript" src="../sources/scripts/jquery-1.3.1.min.js"/>
            <script type="text/javascript" src="../sources/scripts/jquery-ui-personalized-1.6rc6.min.js"/>
            <script type="text/javascript" src="../sources/scripts/jquery.tooltip.pack.js"/>
            <script type="text/javascript" src="../sources/scripts/jquery.draw.js"/>
            <script type="text/javascript" src="../sources/scripts/jquery.jHelperTip.1.0.min.js"/>
            <script type="text/javascript" src="../sources/scripts/jquery.selectboxes.js"/>
            <script src="../sources/scripts/custom_popup.js" type="text/javascript"></script>
            
            
            <script type="text/javascript" src="../sources/scripts/activities_builder.js"/>
            
            <title>BabelWEB : <xsl:value-of select="@title"/></title>
            </head>
            <body>
                <div id="global">
                    <xsl:call-template name="run">
                        <xsl:with-param name="correct-answers" select="responseDeclaration"/>
                        <xsl:with-param name="content" select="itemBody"/>
                    </xsl:call-template>
                </div>
            </body>
                </html>
                </xsl:for-each>
            </xsl:result-document>-->
            
<!--            XML FILE CONVERTED FOR TRANSFORMATION WITH XSLT1, MANIFEST PREPENDED-->
            <xsl:result-document href="{$fileloc}">
                <xsl:value-of select="substring($s,1,148)" disable-output-escaping="yes" />
                <bw:babelweb-data>
                    <xsl:call-template name="print-manifest">
                        <xsl:with-param name="lang" select="//assessmentItem/@lang"/>
                        <xsl:with-param name="module" select="//assessmentItem/@module"/>
                    </xsl:call-template>
                    <xsl:apply-templates/>
                
                </bw:babelweb-data>
            </xsl:result-document>
            
<!--            EDITION OF XML FILE FOR WEB-->
            <!--<xsl:result-document href="{$editfilename}">
                <html>
                    <head><title>Editing <xsl:value-of select="$filename"/></title>
                        <link rel="stylesheet" type="text/css" href="/Xopus/examples/Simple/css/common.css"/>
                        <script type="text/javascript" src="/Xopus/xopus/xopus.js"></script>
                    </head>
                    <body>
                        <div xopus="true" autostart="true">
                            <xml><x:config xmlns:x="http://www.xopus.com/xmlns/config" version="1.0">
                                <x:javascript src="save.js"/>
                                <x:pipeline xml="{$webAddressToActivities}/sources/{$filename}" 
                                    xsd="/babel-data/online-editing/babel-schema.xsd">
                                    <x:view name="WYSIWYG View">
                                        <x:transform xsl="/babel-data/online-editing/babel-transform-fly.xsl"/>
                                    </x:view>
                                    <!-\-<x:view name="XML View">
                                        <x:transform xsl="/babel-data/online-editing/babel-edit-xml.xsl"/>
                                    </x:view>-\->
                                    
                                </x:pipeline>
                            </x:config></xml>
                        </div>
                    </body>
                </html>
                
            </xsl:result-document>-->
            
        </xsl:for-each>
        
    </xsl:template>
    
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
    
    <!-- **************************************
        intro popups
        ************************************** -->
    
    <xsl:template match="toActivity">
        <xsl:copy>
            <xsl:apply-templates select="init" mode="hover"/>
            <xsl:apply-templates select="description" mode="hidden"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="init" mode="hover">
        <xsl:copy>
            <xsl:variable name="id" select="concat(parent::node()/generate-id(),//assessmentItem/@lang)"/>
            <xsl:attribute name="id">
                <xsl:value-of select="$id"/>
            </xsl:attribute>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="description" mode="hidden"><xsl:copy>
        <xsl:variable name="id" select="concat(parent::node()/generate-id(),//assessmentItem/@lang)"/>
        <xsl:attribute name="id">
            <xsl:value-of select="$id"/>
        </xsl:attribute>
        <xsl:attribute name="class">
            <xsl:value-of select="@class"/>
        </xsl:attribute>
        <xsl:apply-templates/>
    </xsl:copy>
    </xsl:template>
    
    <!-- **************************************
        persistent popups
        ************************************** -->
    
    <xsl:template match="popup">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:apply-templates select="init"/>
            <xsl:apply-templates select="description"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="init">
        <xsl:copy>
            <xsl:variable name="id" select="concat(parent::node()/generate-id(),//assessmentItem/@lang)"/>
            <xsl:attribute name="id">
                <xsl:value-of select="$id"/>
            </xsl:attribute>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="description">
        <xsl:copy>
            <xsl:variable name="id"
                select="concat(parent::node()/generate-id(),//assessmentItem/@lang)"/>
            <xsl:attribute name="id">
                <xsl:value-of select="$id"/>
            </xsl:attribute>
            <xsl:attribute name="class">
                <xsl:value-of select="@class"/>
            </xsl:attribute>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    
    <!-- **************************************
        ************************************** -->
    
    <xsl:template match="text-hint">
        <xsl:copy>
            <xsl:variable name="id" select="self::node()/generate-id()"/>
            <xsl:attribute name="id">
                <xsl:value-of select="$id"/>
            </xsl:attribute>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="image-hint">
        <xsl:copy>
            <xsl:variable name="id" select="self::node()/generate-id()"/>
            <xsl:attribute name="id">
                <xsl:value-of select="$id"/>
            </xsl:attribute>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="radio-group">
        <xsl:copy>
            <xsl:variable name="id" select="self::node()/generate-id()"/>
            <xsl:attribute name="id">
                <xsl:value-of select="$id"/>
            </xsl:attribute>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="autohint-shuffle">
        <xsl:copy>
            <xsl:variable name="id" select="parent::node()/@identifier"/>
            <xsl:attribute name="name">
                <xsl:value-of select="$id"/>
            </xsl:attribute>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    
</xsl:stylesheet>










